const Service = require('egg').Service;

class BrokerService extends Service {
	async getBroker() {
		const {
			app,
			ctx
		} = this;
		const {
			keyword
		} = ctx.query;
		let sql = `select * from broker where 1=1 `
		if (keyword) {
			sql += `and name like "%${keyword}%" `
		}
		const data = await app.mysql.query(sql)
		return data
	}
	async delBroker() {
		const {
			ctx,
			app
		} = this;
		const data = await app.mysql.delete('broker', {
			id: ctx.params.id
		}); // 根据id删除
		return data
	}
	async addBroker() {
		const {
			ctx,
			app
		} = this;
		const data = await app.mysql.insert('broker', {
			...ctx.request.body
		})
		return data;
	}
	async editBroker() {
		const {
			ctx,
			app
		} = this;
		const data = await app.mysql.update('broker', {
			...ctx.request.body,
		})
		return data;
	}
}

module.exports = BrokerService;